home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-08 | 45.5 KB | 1,340 lines |
- ViRCScript Documentation (for Visual IRC '96 0.60 and above) - Revision 10
- ==========================================================================
-
- Introduction
- ============
-
- What is ViRCScript? ViRCScript (from now on abbreviated to VS) is the scripting
- language supported by ViRC '96. VS is similar to BASIC, C, VPL, and ircII's
- scripting language. You use VS to write code for events and aliases. In 0.60,
- the ViRCScript interpreter is around 90% complete. Newer versions will add more
- functionality, however, I will endeavour to ensure that these new changes don't
- break your old code.
-
- VS is 100% written by myself. I've used no code from anywhere else or custom
- controls in my parser, numerical evaluator, or anything else. This means that
- if you have any problems, you have no-one to blame them on but me. >:-> (That
- said, no-one has reported any real problems in ViRCScript. It seems to be the
- most stable portion of V96 I've written so far).
-
- What's new in this release of ViRCScript?
- -----------------------------------------
-
- Except the ++ (increment) and -- (decrement) operators and performance
- improvements, there's little new in this release of ViRCScript. However, much
- functionality that existed in previous releases wasn't properly documented
- here, so I've tried to remedy that now, making sure that every function in
- V96's internal function table is documented.
-
- Syntax
- ------
-
- Place one VS instruction on each line. Lines beginning with # or // are assumed
- to be comments, and are ignored. Otherwise the line is parsed and executed.
- Statements and functions are case-insensitive, except for variables, which are
- case-sensitive, i.e. $x is not the same as $X. Numerical parameters to
- functions can be supplied in decimal, or in hex by prefixing with a $. For
- example, to get a random number between 0 and 254, you could use:
-
- $rand(255)
-
- Or:
-
- $rand($FF)
-
- Variables
- ---------
-
- Variables are allocated and assigned with the @ operator, and deallocated with
- the -@ operator. Examples:
-
- @ $x = Hello everybody!!
- -@ $x
-
- Wildcards are supported when using -@, and this is very useful with arrays.
- Say, for example, you defined the following array:
-
- @ $greeting.0 = Hello
- @ $greeting.1 = Hi
- @ $greeting.2 = Yo
- @ $greeting.3 = Greetings
- @ $greeting.4 = Howdy
-
- You could delete the whole thing in one go with the single statement:
-
- -@ $greeting.*
-
- Or, as the array element numbers are only 1 figure long:
-
- -@ $greeting.?
-
- You should always deallocate used variables at the end of your scripts, as
- "dangling" variables will make script parsing slower and take up memory.
-
- In addition, ViRC '96 0.34 and above support stored variables. These are like
- regular variables, except their values are stored in the registry, and hence
- are retained if V96 is closed down and then restarted. Define a stored
- variable exactly like a regular variable, except use @s instead of @. Undefine
- a stored variable by using -@s instead of -@. For example:
-
- @s $script_ver = YTooLZ for ViRC '96 version 4.91
-
- The value of $script_ver will not be lost when V96 is closed down.
-
- You can evaluate a numeric expression by enclosing it in $( and ). For example:
-
- @ $x = $(1+1)
-
- You can evaluate expressions as complex as you want, including variables and
- functions, for example:
-
- @ $x = $((((16/2)*$strpos(xt $3-))+(18/$dfactor))-1)
-
- $() is not required in if/while/for statements, as the conditions are evaluated
- numerically anyway.
-
- In addition, V96 0.60 and above support the C-style ++ and -- operators. What's
- more, they're not just a pretty face - they execute a LOT, LOT faster than the
- equivalent code @ $i = $($i + 1), and are ideal for loops and things. For
- example, to increment $x by one, you could use:
-
- $x++
-
- Please not that you DO NOT prefix this with an @, like with other variable
- assignments!!
-
- Pseudovariables (Pvars) are also supported in aliases and events. A typical
- Pvar looks like $0, or $7-, and represents a parameter supplied to the alias or
- event. $n means the n'th parameter. With events, the first word of the line of
- text received from the server is $0, the second word $1, and so on. With
- aliases, the alias command is $0, the first parameter supplied is $1, the
- second parameter supplied is $2, and so on. In addition, an expression like
- $2- means "the second parameter and all subsequent parameters". So, $2- is
- equal to $2 $3 $4 $5 $6 $7 $8 .... $n. More about this later.
-
- V96 also maintains a number of built-in variables. These are as follows:
-
- $ver The current version of V96, e.g. 0.60
- $build The current version V96 in integer form, e.g. 60
- $N Your nickname
- $U Your username
- $H Your hostname
- $ip Your IP address
- $server The server you're connected to
- $C The channel the user types the event in. If the event
- is typed in a server window, $C is set to . (a period).
- $null Equals nothing. Use to set variables to nothing, e.g.
- @ $x = $null
-
- A number of constants are also maintained:
-
- \b Bold
- \u Underline
- \i Italic
- \A ASCII character 1 - (used for CTCPs)
-
- Note that V96 supports a number of simultaneous server connections, even if
- you're on the same channel on both servers!! And you can have a different
- nickname on each server. So what nickname does $N correspond to? The answer is,
- the active context's nickname. If you use $N from an event, $N is the nickname
- on the server which caused the event. $N in an alias refers to the nickname of
- the current server connection relating to the window you typed the alias in.
- For example, $N in a channel window would be your nick on the server that
- you're on that channel on. Sounds confusing? Just use $N and it should work as
- you expect it to every time. =]
-
- What about $+ you may ask. As most of you know, in mIRC, PIRCH etc. you need
- $+ to trim spaces ... in other words, you'd need something like this:
-
- *** $nick ( $+ $user $+ @ $+ $host $+ ) has joined channel $3
-
- To display this:
-
- *** MeGALiTH (megalith@jimc.demon.co.uk) has joined channel #quake
-
- In V96, spaces are not required before variables and functions, because of its
- intelligent parser. So you could do something like this, which looks much
- neater:
-
- *** $nick ($user@$host) has joined channel $3
-
- The above would totally foul up mIRC and PIRCH. In fact, V96 doesn't care what
- you have before or after a variable. This would work:
-
- alkjdsjkadjka$nickjhdakajsdakjdhkjadhk
-
- So, the skeptic asks, in this case, how does V96 know whether you want the
- variable $nick, $nickj, $nickjhdak, or what? The answer is, it reads your mind.
- Well, no, it doesn't - it actually sorts the variables alphabetically and
- parses them in reverse order (you what?!??!). This ends up with the right
- result. If a variable $nickjhd exists, then it'll parse the line as containing
- $nickjhd, otherwise it'll do $nickjh, and if that doesn't exist, $nickj ... and
- so on, all the way down to $n. So, again, as with the multiple-$N-on-multiple-
- servers thing I described above, V96 is intelligent enough to work out what
- you're trying to do, and do it correctly.
-
- ViRCScript Statements
- =====================
-
- TEXTOUT statement
- -----------------
-
- Usage: TextOut [> window] <colour> <text ...>
-
- Displays some text in a window. If the window name is left out, TextOut will
- output the text to all channel windows, unless there are none open, in which
- case the text will be displayed in the server window. Specifying a channel name
- will display the text in that channel (or the server window if the channel
- doesn't exist). Specifying . will output the text to the server notices window.
- Specifying anything else will create a query window with that name (if it
- doesn't already exist) and output the text there. You can use a query window
- created "on-the-fly" like this as a simple text output window for your scripts.
-
- Colour may be specified in four ways.
-
- (1) Specifying a colour constant. The following colour constants
- are supported (this will be familiar to Delphi 2.0 users):
-
- clBlack Black
- clMaroon Maroon
- clGreen Green
- clOlive Olive green
- clNavy Navy blue
- clPurple Purple
- clTeal Teal
- clGray Gray
- clSilver Silver
- clRed Red
- clLime Lime green
- clBlue Blue
- clFuchsia Fuchsia
- clAqua Aqua
- clWhite White
-
- clBackground Current color of your Windows background
- clActiveCaption Current color of the title bar of the active window
- clInactiveCaption Current color of the title bar of inactive windows
- clMenu Current background color of menus
- clWindow Current background color of windows
- clWindowFrame Current color of window frames
- clMenuText Current color of text on menus
- clWindowText Current color of text in windows
- clCaptionText Current color of the text on the title bar of the active window
- clActiveBorder Current border color of the active window
- clInactiveBorder Current border color of inactive windows
- clAppWorkSpace Current color of the application workspace
- clHighlight Current background color of selected text
- clHightlightText Current color of selected text
- clBtnFace Current color of a button face
- clBtnShadow Current color of a shadow cast by a button
- clGrayText Current color of text that is dimmed
- clBtnText Current color of text on a button
- clInactiveCaptionText Current color of the text on the title bar of an inactive window
- clBtnHighlight Current color of the highlighting on a button
- cl3DDkShadow Windows 95 only: Dark shadow for three-dimensional display elements
- cl3DLight Windows 95 only: Light color for three-dimensional display elements (for edges facing the light source)
- clInfoText Windows 95 only: Text color for tooltip controls
- clInfoBk Windows 95 only: Background color for tooltip controls
-
- The second half of the colors listed here are Windows system
- colors. The color that appears depends on the color scheme users
- are using for Windows. Users can change these colors using the
- Control Panel in Program Manager. The actual color that appears
- will vary from system to system. For example, the color fuchsia
- may appear more blue on one system than another.
-
- For example, to output some blue text in the server window:
-
- TextOut > . clBlue blah blah blah ...
-
- (2) Specifying an event colour constant. Event colour constants
- correspond to the colour of the corresponding event type the user
- has selected in Client setup/Colours and fonts. This allows scripts
- that you write to automatically adjust to the colours the user
- wants. The following event colour constants are available.
-
- ecJOIN Join colour
- ecPART Part colour
- ecQUIT Quit colour
- ecTOPIC Topic change colour
- ecMODE Mode change colour
- ecKICK Kick colour
- ecPRIVMSG Private message colour
- ecNOTICE Notice colour
- ecCTCP CTCP colour
- ecACTION Action colour
- ecNICK Nick change colour
- ecMyChanText Colour of channel text the user has entered himself
- ecChanText Colour of channel text other users have entered
- ecMyQueryText Colour of query text the user has entered himself
- ecQueryText Colour of query text other users have entered
- ecServText Colour of server text
- ecError Colour of error text
- ecScript or ecXDCC Colour of script (e.g. XDCC) status messages
-
- For example:
-
- TextOut ecKICK This text will appear in the same colour as channel kicks do.
-
- (3) Specifying a hex RGB value, in the form $bbggrr.
-
-
- For example:
-
- TextOut $0000FF This text is red.
- TextOut $00FF00 This text is green.
- TextOut $FF0000 This text is blue.
- TextOut $00FFFF This text is yellow.
- TextOut $FFFFFF This text is white.
- TextOut $000000 This text is black.
-
- (4) Specifying a decimal RGB value. This is rather useless, unless
- you're specifying the text colour as a random number, e.g.
-
- TextOut $rand($FFFFFF) This text appears in a random colour.
-
- IF/ELSE/ENDIF statements
- ------------------------
-
- Usage: if (condition)
- ...
- [else]
- [...]
- endif
-
- Executes a block of code only if a given condition is true. Multiple conditions
- can be specified, and are separated with && (boolean AND) or || (boolean OR)
- operators. If the condition is false and an ELSE block exists, this code is
- executed. The following operators are supported:
-
- Op | Meaning
- ------+--------------------------
- == | Equal to
- != | Not equal to
- > | Greater than
- < | Less than
- >= | Greater than or equal to
- <= | Less than or equal to
- + | Plus
- - | Minus
- * | Multiply
- / | Divide
- ^^ | Power
- && | Boolean AND
- || | Boolean OR
- ! | Boolean NOT
-
- If you're used to C, you'll have no problems. Expressions can be as simple or
- as complex as you like - you can nest many levels of brackets if you need to.
-
- IF can be used to compare numeric expressions or string expressions. All string
- expressions must be enclosed in []'s, just as in ircII.
-
- Numeric expression example:
-
- if (2+3 == 5)
- TextOut clBlue Of course it does!!
- endif
-
- String expression example:
-
- if ([hello] == [goodbye])
- TextOut clBlue Not unless the laws of physics have changed.
- endif
-
- Boolean operators may also be used. && = and, || = or, ! = not.
-
- if (2+3 == 5) && (4*2 == 8)
- TextOut clBlue Naturally.
- endif
-
- In fact, you'll rarely have to use the ! operator. You'll see that the
- following two statements are equivalent:
-
- if ([$x] != [$y])
- if !([$x] == [$y])
-
- Note that spaces are not required (they are ignored by the parser), but may be
- included for clarity. For example:
-
- if (2+3==5)&&(10*17==170)&&((5>=2)||(9=16))
-
- That's perfectly correct, but impossible to read ;). Adding spaces makes the
- statement far clearer:
-
- if (2+3 == 5) && (10*17 == 170) && ((5 >= 2) || (9 == 16))
-
- You must enclose string expressions in []'s. This prevents V96 from trying to
- numerically evaluate the text between the [ and the ]. For example:
-
- if ([$nick] == [hello])
- TextOut clBlue Blah!!
- endif
-
- An ELSE construction is supported too.
-
- @ $x = $?="What does IRC stand for?"
- if ([$x] == [Internet Relay Chat])
- TextOut clGreen Well done!!
- else
- TextOut clRed Wrong!!
- endif
-
- WHILE/ENDWHILE statements
- -------------------------
-
- Usage: while (condition)
- ...
- endwhile
-
- Executes a block of code while condition is true. If condition is false
- initially, the while block will be skipped. See the IF/ELSE/ENDIF statement for
- details on how to specify conditions. Beware, as a condition that's always true
- will produce an infinite loop and will lock V96 up!! For example:
-
- while (1)
- endwhile
-
- In fact, now ViRCScript has a C-like for statement, while is largely
- superflous. In fact:
-
- while (condition)
- ...
- endwhile
-
- Is functionally-identical to:
-
- for (;condition;)
- ...
- endfor
-
- The for statement is used only with a condition, with no initial statement and
- no increment statement.
-
- FOR/ENDFOR statements
- ---------------------
-
- Usage: for (initial statement;condition;increment statement)
- ...
- endfor
-
- V96's for statement behaves exactly like the for statement in C/C++, so you
- should have no problems. For example, the following C code:
-
- for (int i = 0; i < 10; i++)
- printf("%d", i);
-
- Is equivalent to the following ViRCScript code:
-
- for (@ $i = 0; $i < 10; $i++)
- TextOut clBlue $i
- endfor
-
- (Note the use of the new ++ operator here!!)
-
- Note that variables created by the for statement (e.g. the $i above) are not
- deallocated at the end, so the following statement should really be added to
- the end of the above code fragment:
-
- -@ $i
-
- The for and while statements are often interchangable. In fact:
-
- for (x;y;z)
- ...
- endfor
-
- Is equivalent to:
-
- x
- while (y)
- ...
- z
- endwhile
-
- However, usage of for is much neater in many cases than while. Note that, just
- like C, misuse of for can lock the system up!! Compare the following C
- fragment:
-
- for (;;)
- ...
-
- And the following ViRCScript:
-
- for (;;)
- ...
- endfor
-
- Both will lock the system up in an infinite loop. So be careful!!
-
- ALIAS/ENDALIAS statements
- -------------------------
-
- Usage: alias <name> [hotkey]
- ...
- endalias
-
- Defines an alias (similar to a procedure or function in other languages).
- The parameters of the alias are passed in as $1, $2, $3 and so on, and the
- actual alias command itself is passed in as $0. The channel window the alias is
- typed in is passed in as $C. $C is set to . if the alias is run from the server
- notices window. Optionally, hotkey may be specifed (e.g. F3, or Ctrl+Shift+Z).
- When hotkey is pressed, the alias will be executed as if it were typed in the
- current window.
-
- Aliases can be very useful, for example, consider this:
-
- Alias GO
- Connect
- Join #quake
- Msg Bot !op
- Mode #quake +ooo User1 User2 User3
- Part #quake
- Quit
- EndAlias
-
- When the user types /go, V96 will connect to the server, join #quake, /msg Bot
- for ops, op User1, User2 and User3, leave #quake, and quit IRC. Aliases can
- also be used as functions. Simply assign a value to $fresult as the value of
- the function. For example, consider this, a function to pick and return a
- random boolean value, either True or False:
-
- Alias RANDBOOL
- @ $x = $rand(2)
- if ($x == 1)
- @ $fresult = True
- else
- @ $fresult = False
- endif
- EndAlias
-
- Now:
-
- TextOut clBlue Random boolean expression: $randbool()
-
- Another use for aliases is executing frequently-used single commands. For
- example, say you're on #quake, and are frequently asked what the current
- version of Quake is. You could make an alias like this:
-
- Alias QUAKEVER
- Say $C $1: The current version of Quake is 1.01.
- EndAlias
-
- Then, for example, if Dnormlguy asked what the latest version of Quake was,
- in the #quake channel window, you could just type /quakever Dnormlguy. V96
- would expand $C to #quake, and $1 to the first parameter, Dnormlguy. So, the
- text "Dnormlguy: The current version of Quake is 0.92" to the channel.
-
- EVENT/ENDEVENT statements
- -------------------------
-
- Usage: event <name> <priority> "<mask>"
- ...
- endevent
-
- Defines an event. Events are the most powerful feature of VS, although also the
- hardest to grasp. The best way to get a feel for events is to look through
- V96's built-in events and see how they work.
-
- Name is just an arbitrary name to assign to the event. You can call events
- anything you like. Mask is the text that must be received from the server to
- trigger the event, and can include wildcards. Priority is the event priority,
- which confuses many people.
-
- Parameters are passed into the event with the first word received from the
- server as $0, the second word as $1, etc. In addition, the sender of the
- message's nick is stored in $nick, the username in $user, and the hostname
- in $host. If the message originates from the server, $nick is the server, and
- $user and $host are empty. Example:
-
- :greygoon!bhess@wilma.widomaker.com NOTICE MeGALiTH :You're not opped!!
-
- This is what the server sends when greygoon sends the notice
- "You're not opped!!" to MeGALiTH. So, the parameter breakdown would be as
- follows:
-
- $0 :greygoon!bhess@wilma.widomaker.com
- $1 NOTICE
- $2 MeGALiTH
- $3 :You're
- $4 not
- $5 opped!!
-
- $nick greygoon
- $user bhess
- $host wilma.widomaker.com
-
- Thus the activation mask for a NOTICE is "* NOTICE *". This basically means:
- $0 can be anything, $1 must be NOTICE, and $2 can be anything. Any parameters
- that are not supplied can be anything - in fact, the * at the end of the mask
- is not really necessary, but is included for clarity.
-
- Now for how priorities work ... basically, V96 will execute a maximum of ONE
- event handler for every ONE line of server text. If two events are defined,
- both of whose masks match the server text, V96 will execute the event with the
- higher priority. For example, consider this. V96 comes with two events, one for
- handling private messages, and one for handling channel messages. Look at the
- handlers for each.
-
- Private messages:
-
- Event PrivateMessage 4 "* PRIVMSG *"
-
- Channel messages:
-
- Event ChannelMessage 5 "* PRIVMSG #*"
-
- A typical private message received from the server may look like this:
-
- :nick!user@host PRIVMSG YourNick :hello!!
-
- A typical channel message might look like this:
-
- :nick!user@host PRIVMSG #quake :hello all!!
-
- Now, remember that V96 will only execute one event per line of server text. If
- the server receives a line of private text, the only event that applies is
- the PrivateMessage event. The ChannelMessage event's third parameter must begin
- with # for the event to be fired, and this is not the case with a private
- message. So the priority is ignored, because only one event is possible.
- The correct selection of priority is _required_ when two events are defined,
- and one line of server text can match both events: if a CHANNEL message is
- received, you can see that both events apply. A channel message's mask matches
- both * PRIVMSG * and * PRIVMSG #*. So, V96 will see that this line of server
- text matches two events, and will execute the event with the highest priority.
- I realize that priority may be a tricky concept, but hopefully you'll get the
- hang of it in no time. ;)
-
- Note that the <default> event (mask *), which is fired for every line of server
- text that is received, has a priority of 0. This means that the event is only
- executed if NO OTHER EVENTS match the line of server text, because all other
- events have a priority higher than 0.
-
- PARSE/ENDPARSE statements
- -------------------------
-
- Usage: parse text
- ...
- endparse
-
- Parses text into the pseudovariables $0 to $9 for the duration of the parse
- block. Without doubt one of the most powerful commands in ViRCScript. Its use
- is best illustrated by an example:
-
- @ $x = This is a test.
- Parse $x
- TextOut clBlue $0 $1 $2 $3
- TextOut clBlue $3 $2 $1 $0
- EndParse
-
- The following will appear on the screen:
-
- This is a test.
- test. a is This
-
- The values of the pseudovariables are restored to their previous state at the
- end of the parse block. So, they are only valid between Parse and EndParse.
- You must assign them to other variables if you want to use them outside the
- parse block. You may nest as many parse blocks within each other as you like.
-
- What in reality could this be used for? One idea is a #chaos-type question
- game, You have a file called QUESTION.TXT which contains questions and answers
- in the form:
-
- answer question ...
- answer question ...
- answer question ...
-
- And so on. You want some code to pick a random question from the file, putting
- the question in $question and the answer in $answer. The following code would
- do the trick:
-
- @ $x = $randomread(question.txt)
- Parse $x
- @ $answer = $0
- @ $question = $1-
- EndParse
-
- MENUTREE/ENDMENUTREE command
- ----------------------------
-
- Usage: menutree menutype
- [item1]
- [item2]
- ...
- endmenutree
-
- Defines the menu tree for menutype. This command is used to define the
- structure of a menu or popup, before code is assigned to each item. The
- following values for menutype are currently recognized:
-
- MT_MAINMENU - define the tree for the main menu
- MT_SERVERPOPUP - define the tree for the server window popup
- MT_CHANNELTEXT - define the tree for the channel window text pane popup
- MT_CHANNELNICKS - define the tree for the channel window names pane popup
-
- Each item defined between MenuTree and EndMenuTree takes the following format:
-
- ItemName HotKey State Depth Text
-
- ItemName is an arbitrary name to give to the menu item. The name will be used
- again later to define the code when you click on the menu item. HotKey defines
- what hotkey to activate the menu item on. HotKey can be something like F12 or
- Ctrl+Shift+A, or <none> if you don't require a hotkey. Note that HotKey is
- ignored for menus other than MT_MAINMENU. State determines the menu item's
- state. For menu types MT_MAINMENU and MT_SERVERPOPUP, State can take the
- following values:
-
- 0 - Menu item is enabled
- 1 - Menu item is enabled when you're connected to the server, and
- disabled otherwise
- 2 - Menu item is disabled when you're connected to the server, and
- enabled otherwise
- 3 - Menu item is disabled
-
- For menu types MT_CHANNELTEXT and MT_CHANNELNICKS, State can take the following
- values:
-
- 0 - Menu item is enabled
- 1 - Menu item is enabled when you're opped on this channel, and
- disabled otherwise
- 2 - Menu item is disabled when you're opped on this channel, and
- enabled otherwise
- 3 - Menu item is disabled
-
- Depth defines the "depth" of the menu item. For MT_MAINMENU, a depth of 0
- represents an entry on the top menu bar. A depth of 1 is a subitem of the
- closest item above which has a depth of 0. A depth of 2 is a subitem of the
- closest item above that has a depth of 1.
-
- Text is the actual text to display on the menu. If an & is present in Text,
- you can pull the menu down quickly by pressing Alt and the letter after the &.
-
- Here are some example menu tree items, taken from DEFAULT.LIB:
-
- M_FILE <none> 0 0 &File
- M_NEWCONNECT Ctrl+K 0 1 &New connection ...
- M_SETUP <none> 0 1 Client s&etup ...
- M_FSEP1 <none> 0 1 -
- M_EXIT Alt+X 0 1 E&xit
- M_TOOLS <none> 0 0 &Tools
- M_FINGER Ctrl+F 0 1 UNIX &finger ...
-
- Hopefully by comparing this with what you actually see in the program will
- enable you to understand the significance of each field.
-
- MENUITEM/ENDMENUITEM command
- ----------------------------
-
- Usage: menuitem ItemName on MenuType
-
- Defines the ViRCScript code to trigger when the user clicks on the menu item
- Name on the menu type MenuType. MenuType can take the same values here as with
- the MenuTree command detailed above. In the above example, one of the item
- lines between MenuTree and EndMenuTree is:
-
- M_NEWCONNECT Ctrl+K 0 1 &New connection ...
-
- To define the ViRCScript code to actually make this open a new server window,
- you would use:
-
- MenuItem M_NEWCONNECT on MT_MAINMENU
- NewServerWindow
- EndMenuItem
-
- For a good example of how this works, see DEFAULT.LIB.
-
- Menu items on a MenuType of MT_CHANNELNICKSPOPUP are supplied with the nickname
- selected in the names pane of the currently-active channel window as the
- parameter $1. For example:
-
- MenuItem M_HELLO on MT_CHANNELNICKSPOPUP
- Say $C Hello, $1!!
- EndMenuItem
-
- If the user clicks on abc123's nick in a channel window, and then right-clicks
- and selects M_HELLO from the popup menu, the text "Hello, abc123!!" will be
- said to the channel.
-
- UPDATEMENUS command
- -------------------
-
- Usage: updatemenus
-
- Recreates all menus and popups from the in-memory menu trees and writes the
- trees to the registry. After you have changed menu(s) with MenuTree and
- MenuItem statements, you must use this command for your changes to take effect
- properly. Failure to execute this command when you've finished altering the
- menus can cause unwanted side-effects, as the in-memory menu trees and the
- actual menus and popups become desynchronized from each other.
-
- NAME statement
- --------------
-
- Usage: name text
-
- Names your script text. This isn't really a statement at all. It's used by the
- script loader to display your script's name in the loading progress dialog box.
- It's recommended you use NAME to give your script a sensible name at the top of
- the file, so people know what they're loading.
-
- MESSAGEBOX command
- ------------------
-
- Usage: MessageBox text
-
- Displays a message box on the screen with an OK button, with text as its
- contents. Use this in scripts to inform the user of something.
-
- CREATEFILE command
- ------------------
-
- Usage: CreateFile filename
-
- Creates filename, or truncates it to 0 bytes if it already exists.
-
- APPENDTEXT command
- ------------------
-
- Usage: AppendText filename text
-
- Appends text to the end of filename. The command will do nothing if filename
- does not exist.
-
- SETINPUTLINE command
- --------------------
-
- Usage: SetInputLine channel text
-
- Sets the command entry box's contents of channel to text. If you wish to set
- the contents of the server window's entry box, specify . as channel (a period).
-
- EVAL command
- ------------
-
- Usage: Eval command
-
- Normally, commands are evaluated before executing them. Placing EVAL before a
- command line causes the line to be evaluated twice before executing. You'd
- probably never have to use this in your scripts, except when evaluating
- expressions that are stored somewhere else, for example, a line in a file.
- To get a random line from a file, evaluate that line, and store in $x, you'd
- use:
-
- Eval @ $x = $randomread(filename.txt)
-
- BREAK command
- -------------
-
- Usage: Break
-
- Quits from the currently-executing code block. A code block is something like
- the code between if/endif, while/endwhile, parse/endparse etc. If this
- statement is executed outside a code block, execution of your script routine
- will stop (see the HALT command).
-
- HALT command
- ------------
-
- Usage: Halt
-
- Similar to the BREAK command, only exits from ALL code blocks and terminates
- execution of your script.
-
- FALLTHROUGH command
- -------------------
-
- Usage: FallThrough
-
- This powerful command makes event programming much easier. If you've defined a
- special event, but you only want it to execute sometimes, and the rest of the
- time you want the system to behave as if the event was never defined, you can
- use the FallThrough statement to pass the event down to a handler of lower
- priority. A good example is if you're writing, for example, a channel
- statistics script, which catches WHO replies (* 352 *) and processes them,
- without displaying them in the server notices window. However, if the user has
- not typed /chanst, then the regular <default> event should be executed to
- display the WHO on the screen in the normal way. The event would be defined
- like this:
-
- Event ChanStatWHOReply 5 "* 352 *"
- if ($doingchanst)
- ...
- else
- FallThrough
- endif
-
- YIELD command
- -------------
-
- Usage: Yield
-
- Polls the Windows message queue and processes waiting messages. If you're
- writing a script that uses a while loop that takes a long time to execute, it
- may be a good idea to use YIELD to prevent the system from locking up while
- your script is executing. For example, the following will lock V96 up:
-
- while (1)
- endwhile
-
- However, the following will not lock V96 up, although it'll slow it down a
- little because it is actually executing the while loop over and over again,
- ad infinitum:
-
- while (1)
- Yield
- endwhile
-
- The YIELD command is very useful when implementing background processing.
- Adding a YIELD statement to a time-consuming for loop will allow other tasks to
- continue running in the background while the for loop executes.
-
- IRC commands
- ------------
-
- Usage: [^][*]command ...
-
- Regular IRC commands may be used in VS (of course ;), only the slash prefix is
- optional and should be left out, and the code looks neater without it. In
- addition, the command can be prefixed with ^, * or ^*.
-
- A prefix of ^ surpresses the output of any text that the command directly
- causes. For example, V96 contains code in its MSG command to display the
- message you're sending on the screen. ^MSG will send the message, but surpress
- the next output.
-
- A prefix of * passes the command straight into V96's built-in command
- interpreter, without executing any aliases. This is very useful if you're
- trying to override built-in commands, as, for example, if you want to call
- V96's MSG command in your new MSG alias, you need to call the command as *MSG
- to avoid the alias calling itself recursively.
-
- Both prefixes can be combined as ^*. Please note that a prefix of *^ is
- INVALID, and will cause an error.
-
- The following code will change the text displayed when the user uses the /msg
- command to something a little more fancy, demonstrating how to override a
- built-in command:
-
- Alias MSG
- TextOut ecPRIVMSG [*>\b$1\b<*]\t$2-
- ^*Msg $1-
- EndAlias
-
- ViRCScript Functions
- ====================
-
- Currently, only a few functions are implemented, however, many more functions
- will be implemented in future versions.
-
- Getting input from the user
- ---------------------------
-
- $? pseudofunction
- -----------------
-
- Usage: $?="prompt"
-
- Prompts the user to enter some text, displaying prompt in the text entry dialog
- box. This is similar to mIRC's $? "function".
-
- STRTRIM function
- ----------------
-
- Usage: $strtrim(text)
-
- Removes control characters and the preceding colon, if present, from text. This
- is very useful, as many lines received from the IRC server contain parameters
- prefixed by a colon.
-
- Example: Consider this line of server text.
-
- :nick!user@host PRIVMSG #channel :well, what's up everybody!!
-
- To extract the actual message sent to the channel correctly, you would use
- $strtrim($3-).
-
- DECODEPINGINTERVAL function
- ---------------------------
-
- Usage: $decodepinginterval(integer)
-
- Converts the ping-encoded integer specified to a human-readable time interval.
- This function is only useful to decode received pings. To decode normal time
- intervals, use the DECODEINTERVAL function.
-
- DECODEINTERVAL function
- -----------------------
-
- Usage: $decodeinterval(integer)
-
- Converts the integer supplied as the parameter to a human-readable time
- interval. For example:
-
- $decodeinterval(38) = 38 seconds
- $decodeinterval(60) = 1 minute
- $decodeinterval(61) = 1 minute 1 second
- $decodeinterval(3728) = 1 hour 2 minutes 8 seconds
-
- UPPER function
- --------------
-
- Usage: $upper(text)
-
- Converts the given text to upper case. For example:
-
- $upper(blah) = BLAH
-
- LOWER function
- --------------
-
- Usage: $lower(text)
-
- Converts the given text to lower case. For example:
-
- $lower(BLAH) = blah
-
- STRPOS function
- ---------------
-
- Usage: $strpos(needle haystack)
-
- Finds needle within haystack, and returns the character position of needle.
- 0 is returned if needle is not found in haystack. For example:
-
- $strpos(cd abcdefg) = 3
- $strpos(blah hahahahha) = 0
-
- RAND function
- -------------
-
- Usage: $rand(n)
-
- Returns a random integer in the range 0 to n - 1. For example, $rand(1000) may
- return 0, 273, or 879, but never -112 or 1000.
-
- RANDOMREAD function
- -------------------
-
- Usage: $randomread(file)
-
- Returns a randomly-selected line from file. This is useful for quote or slap
- scripts.
-
- ISON function
- -------------
-
- Usage: $ison(nick channel)
-
- Returns true (1) if nick is on channel, otherwise returns false (0). Example:
-
- if $ison(MeGALiTH #quake)
- Msg MeGALiTH Hi there!!
- endif
-
- ISOP function
- -------------
-
- Usage: $isop(nick channel)
-
- Returns true (1) if nick is an op on channel. If nick is a non-op on channel,
- or if nick is not on channel, returns false (0).
-
- WILDMATCH function
- ------------------
-
- Usage: $wildmatch(text mask)
-
- Matches text against mask, which can contain wildcards. Examples:
-
- $wildmatch(blah *lah) = 1
- $wildmatch(blah bla*) = 1
- $wildmatch(blah *la*) = 1
- $wildmatch(blah *) = 1
- $wildmatch(blah *hah) = 0
-
- Mask comparisons are case-insensitive. text may contain spaces. mask, however,
- may not.
-
- MASKMATCH function
- ------------------
-
- Usage: $maskmatch(text mask)
-
- Matches text against mask. Use MASKMATCH, and _not_ WILDMATCH, if you're trying
- to match a nick!user@host-style mask. Example:
-
- $maskmatch(MeGALiTH!~megalith@jimc.demon.co.uk *!*megalith@*demon.co.uk) = 1
-
- Mask comparisons are case-insensitive.
-
- NICKCOUNT function
- ------------------
-
- Usage: $nickcount(channel)
-
- Returns the number of users on channel. If channel doesn't exist, the function
- will return 0.
-
- OPCOUNT function
- ----------------
-
- Usage: $opcount(channel)
-
- Returns the number of ops on channel. If channel doesn't exist, or if there are
- no ops, the function will return 0.
-
- PEONCOUNT function
- ------------------
-
- Usage: $peoncount(channel)
-
- Returns the number of peons (non-ops) on channel. If channel doesn't exist, or
- if there are no peons, the function will return 0.
-
- NICKS function
- --------------
-
- Usage: $nicks(channel num)
-
- Returns the num'th user on channel. For example, $nicks(#quake 45) will return
- the nick of the 45th user on channel #quake (the list is sorted
- alphabetically, with ops at the top, followed by peons). If channel doesn't
- exist, or there is no user at num (i.e. if num is less than 1 or greater than
- $nickcount), the function will return nothing.
-
- OPS function
- ------------
-
- Usage: $ops(channel num)
-
- Returns the num'th op on channel. For example, $ops(#quake 3) will return the
- nick of the 3rd op on channel #quake (the list is sorted alphabetically). If
- channel doesn't exist, or there is no op at num (i.e. if num is less than 1 or
- greater than $opcount), the function will return nothing.
-
- PEONS function
- --------------
-
- Usage: $peons(channel num)
-
- Returns the num'th peon (non-op) on channel. For example, $peons(#quake 19)
- will return the nick of the 19th peon on channel #quake (the list is sorted
- alphabetically). If channel doesn't exist, or there is no peon at num (i.e. if
- num is less than 1 or greater than $peoncount), the function will return
- nothing.
-
- FILEEXISTS function
- -------------------
-
- Usage: $fileexists(filename)
-
- Returns true (1) if filename exists, otherwise returns false (0).
-
- SUBSTR function
- ---------------
-
- Usage: $substr(text start num)
-
- Returns num characters at start from text. Exactly equivalent to Delphi's
- Copy(text, start, num) function or VB's Mid$(text, start, num) function.
- Example:
-
- $substr(abcdef 2 3) = bcd
-
- GETINPUTLINE function
- ---------------------
-
- Usage: $getinputline(channel)
-
- Gets the current contents of the command entry box in channel. To do this for
- the server notices window, specify . as channel (a period).
-
- LENGTH function
- ---------------
-
- Usage: $length(text)
-
- Returns the length of text in characters. Example:
-
- $length(hello) = 5
-
- CHANNELCOUNT function
- ---------------------
-
- Usage: $channelcount()
-
- Returns the number of open channels.
-
- CHANNELS function
- -----------------
-
- Usage: $channels(num)
-
- Returns the name of open channel number num. For example, if you have one
- channel open, #quake, $channels(1) will return #quake. If the channel number
- num specified does not exist, the function will return nothing.
-
- GETSETTING function
- -------------------
-
- Usage: $getsetting(section value)
-
- This is a very powerful function which allows a script to obtain any ViRC '96
- user setting that it's stored in the registry. For example, the default event
- library that comes with V96, DEFAULT.LIB, uses this function to determine
- whether to output text in a query window or not, depending on whether the user
- has chosen to use a query window or not in the Options tab of the Client Setup
- dialog.
-
- The best way to find the values for section and value is to load up REGEDIT (it
- comes with Windows 95 and NT) and to look in
- HKEY_CURRENT_USER/Software/MeGALiTH Software/Visual IRC '96. All available
- sections are visible there.
-
- Examples:
-
- $getsetting(Options QueryEnabled)
- $getsetting(Options AutoRejoin)
- $getsetting(SOCKS setup Enabled)
- $getsetting(IDENTD setup Port)
-
- GETUSERLEVEL function
- ---------------------
-
- Usage: $getuserlevel(mask)
-
- Returns the userlevel of mask in your userlist. For example, if
- *!*blah@*hah.com is in your userlist with level 3,
- $getuserlevel(user!nablah@spahah.com) would return 3. If the user cannot be
- found in the userlist, the function will return 0.
-
- GETBANLEVEL function
- ---------------------
-
- Usage: $getbanlevel(mask)
-
- Returns the banlevel of mask in your banlist. If the user cannot be found in
- the banlist, the function will return 0.
-
- GETPROTLEVEL function
- ---------------------
-
- Usage: $getprotlevel(mask)
-
- Returns the protlevel of mask in your protlist. If the user cannot be found in
- the protlist, the function will return 0.
-
- TIME function
- -------------
-
- Usage: $time()
-
- Returns the current system time in a human-readable format (hh:mm:ss xx). For
- example, $time() may return 11:52:48 AM.
-
- DATE function
- -------------
-
- Usage: $date()
-
- Returns the current system date in default system format. This format is
- determined by your Windows locale (internationalization) settings, and may be
- something like 17th June 1996.
-
- CTIME function
- --------------
-
- Usage: $ctime()
-
- Used to calculate time intervals, measured in seconds. The actual value
- returned is the number of seconds that Windows has been running, although this
- may change in the future and cannot be relied upon. The number returned by
- $ctime() increases by 1 every second. For example:
-
- @ $x = $ctime()
- for (@ $i = 0; $i < 1000; @ $i = $($i + 1))
- Yield
- endfor
- TextOut clBlue *** An empty 1000-iteration for loop takes $($ctime() - $x) seconds to complete.
-
- Notice how $ctime() is used here to calculate a time interval - the actual
- meaning of the value returned by $ctime() is insignificant.
-
- The $ctime() function can also be used as a timer. For example, to wait for
- 20 seconds before quitting V96, you could use the following code:
-
- @ $x = $ctime()
- while ($ctime() - $x) < 20
- Yield
- endwhile
- Exit
-
- MTIME function
- --------------
-
- Usage: $mtime()
-
- Used to calculate time intervals, measured in milliseconds. Use for measuring
- time intervals. The number returned by $mtime() increases by 1 every
- millisecond.
-
- IDLETIME function
- -----------------
-
- Usage: $idletime()
-
- Returns the amount of time the user has been idle for in seconds. Can be used
- to implement auto-away scripts. For example, the following code will wait until
- the user has been idle for 2 minutes (120 seconds) and will then set him away:
-
- while ($idletime < 120)
- Yield
- endwhile
- Away Automatically set away after 2 minutes
-
- IDLEMTIME function
- ------------------
-
- Usage: $idlemtime()
-
- Returns the amount of time the user has been idle for in milliseconds. The same
- as $idletime(), only returns a value in milliseconds rather than seconds.
-
- CURRENTCHANNEL function
- -----------------------
-
- Usage: $currentchannel()
-
- Returns the name of the channel window that currently has the focus. If a
- channel window does not have the focus, this function will return . (a period).
- Note that, in an alias, $C and $currentchannel() are equivalent, however, in an
- event, $currentchannel() returns the correct value, whereas $C is undefined.
- Useful if you want to write some text to the channel window the user currently
- has the focus set to (so he/she won't miss the text!!).
-
- ISQUERYING function
- -------------------
-
- Usage: $isquerying(nick)
-
- Returns 1 if a query window is currently open for nick, and 0 otherwise.
-
- ASC function
- ------------
-
- Usage: $asc(char)
-
- Returns the ASCII value for char. For example, $asc(A) = 65, as the ASCII code
- for the character A is 65.
-
- CHAR function
- -------------
-
- Usage: $char(value)
-
- Returns the character for value. For example, $asc(65) = A, as the character
- A corresponds to the ASCII code 65.
-
-